home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / 386KEYB.INC < prev    next >
Text File  |  1994-12-02  |  6KB  |  165 lines

  1. ;"Raw" Keyboard handling functions
  2. ;
  3. ; When in "raw" mode you can detect multiple KEY PRESS/RELEASE
  4. ;
  5. extrn _KeybInst:dword
  6.         ; installs RAW keyboard handler and sets Keyboard RAW INPUT mode
  7.         ; so multiple keys press/release can be detected scanning
  8.         ; the keyboard tables returned by _WaitKey and _ScanKeyb
  9.  
  10. extrn _KeybAsciiMode:dword
  11.         ; call this to set the keyboard handling routines back to
  12.         ; ms-dos "tty like" input mode
  13.         
  14. extrn _ReadAscii:dword ; out: al == ascii char read
  15.         ; Waits and reads a single ASCII character
  16.         ; polling the keyboard like in "standard" consolle mode
  17.         ; BE CAREFUL, "extended" codes are automatically discarded!!!!
  18.         ; THIS ROUTINES EXPECTS THE KEYBOARD IN "ASCII MODE"
  19.  
  20. extrn _KeybRawMode:dword
  21.         ; call this to enable "raw" mode
  22.         ; after "ascii" mode input
  23.  
  24.         
  25. extrn _WaitKey:dword  ; out: eax= pointer to keyboard table
  26.         ; waits until a key is pressed/release
  27.         ; and then returns a POINTER to the current keyboard table
  28.         ; n.b. keyboard must be in "raw" mode
  29.        
  30.         ; the keyboard table is a table of 128 bytes, where the n-th byte
  31.         ; contains the status of the n-th keyboard key
  32.         ; bit 0 = 1 == key IS pressed
  33.         ;         0 == key IS NOT pressed
  34.         ; bit 1 = 1 == key HAS BEEN pressed since last time you reset
  35.         ;              this bit
  36.         ; bit 2..7 = always set to zero.
  37.         ; An irq handler sets/resets bit0 for every key pressed/released
  38.         ; but ONLY set bit 1 if a key has been pressed
  39.         ; (you must reset bit1 on your own).
  40.         ; thus....
  41.         ;   0 == not pressed
  42.         ;   3 == currently pressed
  43.         ;   2 == has been pressed AT LEAST one time, currently is released
  44.  
  45.  
  46. KPRESS   = 3
  47. KPRESSED = 2      
  48.         ;   I don't provide routines or macros to read the keyboard table
  49.         ;   but i provide keyboard scancodes for a US keyboards.
  50.         ;   In some countries some alphabetic keys gets placed differently
  51.         ;   but you can trust on the position of cursor,keypad & fn-keys 
  52.         ;   and on the various ESC,ALT,CTRL,SHIFT,BACKSPACE & RETURN keys
  53.         ;   plus "the first row" on the alphanumeric portion
  54.         ;   (that is: the 1,2,...9,0 keys above the alphabetic keys)
  55.         ;   
  56.         ;   HOW TO "READ" A KEY: 
  57.         ;   if for example you want to read status of the ESC key
  58.         ;   and the EDI register contains the offset of _RKB...
  59.         ;
  60.         ;   instruction:                     IF ZERO FLAG is SET after
  61.         ;                                    executing the istruction THEN ...
  62.         ;
  63.         ;   test edi,[edi + _ESC],KPRESSED   This key has been pressed
  64.         ;                                    and maybe is still pressed
  65.         ;                                  
  66.         ;   cmp  edi,[edi + _ESC],KPRESSED   This key has been pressed
  67.         ;                                    AND NOW is NOT pressed
  68.         ;                                    (key pressed, then released)
  69.         ;
  70.         ;   cmp  edi,[edi + _ESC],KPRESS    This key is CURRENTLY pressed
  71.  
  72. extrn _NotAKey:dword
  73.         ; this dword contains a pointer to the current "key not known"
  74.         ; string
  75.         ; if you perform a "raw" read and check the strings pointed by
  76.         ; the _KeyNames table of pointers, every pointer to the same string
  77.         ; pointed by [_NotAKey] is an unknown key.
  78.         ; You should avoid to use unknown keys because they could be
  79.         ; "new" keys or "metakeys" produced by spurious key presses
  80.         ; (see the key read routine ksel contained into 386menu.asm)
  81.  
  82. extrn _KeyNames:dword
  83.         ; _KeyNames IS a pointer TO an array of 128 pointers TO strings
  84.         ; describing the keyboard keys
  85.         ;  i.e. mov ebx,_KeyNames
  86.         ;       mov ecx,key_index
  87.         ;       mov eax,[ebx+ecx*4]
  88.         ;       ; now eax points to a string describing
  89.         ;       ; the key with index ecx
  90.         ;
  91.  
  92. extrn _ScanKeyb:dword ; out: eax= pointer to keyboard table
  93.         ; executes a keyboard scan and updates the keyboard table
  94.         ; returning a pointer to the CURRENT status of the keyboard keys
  95.         ; n.b. keuboard must be in "raw" mode
  96.  
  97. ; N.B. YOU CAN modify the values contained into the table returned by
  98. ;      _WaitKey and _ScanKeyb
  99. ;      (one of the most common things is clearing the HAS_BEEN_PRESSED bit
  100. ;       of a key entry to detect successive presses/releases)
  101. ;      But every time you call _WaitKey and _ScanKeyb you must use the
  102. ;      new pointer returned (in the current implementation it does not change
  103. ;      but it may change in future)( this is a needed feature to support
  104. ;      non-pc keyboards or different keyboard-like input devices)
  105.        
  106. ; RAW KEYBOARD (_RKB) INDEXES of keys that are always expected to be the same
  107. ; on every keyboard
  108.  
  109. _ESC = 1
  110. _1 = 2
  111. _2 = 3
  112. _3 = 4
  113. _4 = 5
  114. _5 = 6
  115. _6 = 7
  116. _7 = 8
  117. _8 = 9
  118. _9 = 0Ah
  119. _0 = 0Bh
  120.  
  121. _F1  = 3Bh
  122. _F2  = 3Ch
  123. _F3  = 3Dh
  124. _F4  = 3Eh
  125. _F5  = 3Fh
  126. _F6  = 40h
  127. _F7  = 41h
  128. _F8  = 42h
  129. _F9  = 43h
  130. _F10 = 44h
  131. _F11 = 57h
  132. _F12 = 58h
  133.  
  134. _ALT       = 38h
  135. _CTRL      = 1Dh
  136. _LSHIFT    = 2Ah
  137. _RSHIFT    = 36h
  138. _CAPSLOCK  = 3Ah
  139. _TAB       = 0Fh
  140. _BACKSPACE = 0Eh
  141. _ENTER     = 1Ch
  142.  
  143. _HOME   = 47h
  144. _UP     = 48h
  145. _PGUP   = 49h
  146. _LEFT   = 4Bh
  147.  
  148. ; this is "5" on the keypad
  149. _CENTER = 4Ch
  150.  
  151. _RIGHT  = 4Dh
  152. _END    = 4Fh
  153. _DOWN   = 50h
  154. _PGDN   = 51h
  155.  
  156. _INS    = 52h
  157. _DEL    = 53h
  158.  
  159. _KMINUS = 4Ah
  160. _KPLUS  = 4Eh
  161.  
  162. _SPACEBAR = 39h
  163.  
  164.  
  165.